package rule

import "regexp"

func init() {
	Register(&alphaNumRule{Regexp: regexp.MustCompile("^[a-z0-9A-Z]+$")})
}

type alphaNumRule struct {
	*regexp.Regexp
}

func (a *alphaNumRule) Name() string {
	return "alphaNum"
}

func (a *alphaNumRule) Check(in *RuleInput) (err error) {
	if v, ok := in.Value.(string); ok && v != "" && a.FindStringIndex(v) != nil {
		return
	}
	return in.Error()
}
